// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.textures;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;

public class TextureBinder {
    public static TextureBinder instance = new TextureBinder();
    public int maxTextureUnits = 0;
    public int[] textureUnitIDs;
    public int textureUnitIDStart = 33984;
    public int textureIndex = 0;
    public int activeTextureIndex = 0;

    public TextureBinder() {
        this.maxTextureUnits = 1;
        this.textureUnitIDs = new int[this.maxTextureUnits];

        for (int _int = 0; _int < this.maxTextureUnits; _int++) {
            this.textureUnitIDs[_int] = -1;
        }
    }

    public void bind(int textureID) {
        for (int int0 = 0; int0 < this.maxTextureUnits; int0++) {
            if (this.textureUnitIDs[int0] == textureID) {
                int int1 = int0 + this.textureUnitIDStart;
                GL13.glActiveTexture(int1);
                this.activeTextureIndex = int1;
                return;
            }
        }

        this.textureUnitIDs[this.textureIndex] = textureID;
        GL13.glActiveTexture(this.textureUnitIDStart + this.textureIndex);
        GL11.glBindTexture(3553, textureID);
        this.activeTextureIndex = this.textureUnitIDStart + this.textureIndex;
        this.textureIndex++;
        if (this.textureIndex >= this.maxTextureUnits) {
            this.textureIndex = 0;
        }
    }
}
